package com.example.demo.test;

import com.example.demo.component.k8s.bean.pod;
import com.example.demo.component.k8s.k8s_client;
import com.example.demo.component.k8s.k8s_client_factory;
import com.example.demo.component.k8s.k8s_client_util;

import java.util.List;

/**
 * @ClassName k8s_test
 * @Description
 * @date 2022/11/8 15:58
 * @Author yanceysong
 * @Version 1.0
 */
public class k8s_test {

    public static void main(String[] args) throws InterruptedException {
        k8s_client k8s_client = k8s_client_factory.get_k8s_client("192.168.75.129");
//        System.out.println("==========namespace==============");
//        k8s_client.get_namespace().forEach(System.out::println);
//        System.out.println("==========pods===================");
//        k8s_client.get_pods().forEach(System.out::println);
//        System.out.println("==========nodes==================");
//        k8s_client.get_node().forEach(System.out::println);
//        System.out.println("==========service================");
//        k8s_client.get_service().forEach(System.out::println);
//        k8s_client.delete_deploy("C:\\Users\\BG264\\Desktop\\busy-box.yaml");
//        k8s_client.create_deploy("C:\\Users\\BG264\\Desktop\\busy-box.yaml");
        //注意与自身的okio jar冲突
//        k8s_client.scale("busy-box", 2);
//        List<deploy> deploys = k8s_client.get_deploy();
//        for (deploy d : deploys) {

//            k8s_client.delete_deploy(v1Deployment);
//            V1Deployment new_deploy = k8s_client_util.get_new_deploy(d, "1.321-general");
//            k8s_client.create_deploy(new_deploy);
//            k8s_client.update_deploy(d.getName(),d.getImage_name(),"1.321-general");
//            k8s_client.scale(d.getName(),1);
//            System.out.println(k8s_client_util.check_deploy_status(k8s_client,d));
//        }
        List<pod> pods = k8s_client.get_pods();
        final String[] commands = {"sh", "-c", ""};
        String aDefault = k8s_client.exec(pods.get(0), "default", "ls -l");
        System.out.println(aDefault);

//        List<deploy> deploys1 = k8s_client.get_deploy();
//        for (deploy d : deploys1) {
//            System.out.println(d.getImage_version());
//        }
//        List<pod> pods = k8s_client.get_pods();
//        for (pod pod : pods) {
//            System.out.println(k8s_client.get_logs(pod.getName(), pod.getContainer_name()));
//            System.out.println(pod);
//            k8s_client.delete_pod(pod.getName());
//            k8s_client.create_pod(k8s_client_util.get_new_v1Pod(pod, "1.321-general"));
//        }
//        pods = k8s_client.get_pods();
//        for (pod pod : pods) {
//            System.out.println(k8s_client.get_logs(pod.getName(), pod.getContainer_name()));
//            System.out.println(pod);
//        }

    }
}
